package pers.gxm.strategy;

public enum Hand {
    ROCK(0,"石头"),SCISSORS(1,"剪刀"),PAPER(2,"布");
    private int handValue;
    private String name;

    private static Hand[] hands = {ROCK,SCISSORS,PAPER};

    private Hand(int handValue,String name){
        this.handValue = handValue;
        this.name = name;
    }

    private int fight(Hand h){
        if(this == h){
            return 0;
        }else if((this.handValue + 1) % 3 == h.handValue){
            return 1;
        }else{
            return -1;
        }
    }

    public boolean isStrongerThan(Hand h){
        return fight(h) == 1;
    }

    public boolean isWeakerThan(Hand h){
        return fight(h) == -1;
    }

    public boolean isBalance(Hand h){
        return fight(h) == 0;
    }

    public static Hand getHand(int handValue){
        return hands[handValue];
    }
    @Override
    public String toString() {
        return name;
    }
}
